
var crawlerNewsData = require('../common/crawler-news-data');

module.exports = {
  showPage: showPage,
  updateMany: updateMany,
  upadteOne: upadteOne
};

function showPage(req, res, next) {

  res.render('admin/crawler-news');

}


function updateMany(req, res, next) {

  var crawlerCount =  Math.floor(req.body.crawlerCount);

  if(!crawlerCount) {
    next();
    return ;
  }

  crawlerNewsData.getNewsData(crawlerCount)

    .then(function(data) {
      console.log(data);
      res.send("更新完成。");
    })

    .catch(function(err){
      console.log(err);
    });

}


function upadteOne(req, res, next) {

  var crawlerUrl = req.body.crawlerUrl;

  if(!crawlerUrl) {
    next();
    return ;
  }

  crawlerNewsData.getArticleData(crawlerUrl)

    .then(function(data) {
      console.log(data);
      res.send("更新完成。");
    })

    .catch(function(err){
      console.log(err);
    });

}